package com.xintonghua.bussiness.ui.fragment.cube.checkingIn;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListView;

import com.alibaba.fastjson.JSONArray;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.adapter.CheckInNextListAdapter;
import com.xintonghua.bussiness.api.HttpCent;
import com.xintonghua.bussiness.api.myinterface.DataCallBack;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.RecodePersonBean;
import com.xintonghua.bussiness.util.MyState;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class CheckInNextActivity extends BaseActivity {

    @BindView(R.id.checkInListView)
    ListView checkInListView;

    private CheckInNextListAdapter adapter;

    private String ids;
    private String type;
    private String time;

    private List<RecodePersonBean> list;

    Unbinder binder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_in_next);
        binder = ButterKnife.bind(this);
        Intent intent = getIntent();
        ids = intent.getStringExtra("ids");
        type = intent.getStringExtra("type");
        time = intent.getStringExtra("time");
        setTitle(type);
        HttpCent.getInstance(this).getRecordListByIds(ids, type, time + "23:59:59", this, MyState.requestOne);
    }

    public void setTitle(String type) {
        onSimpleActionBar();
        switch (type) {
            case "weidaka":
                setSimpleActionBar("未打卡");
                break;
            case "zhengchang":
                setSimpleActionBar("正常打卡");
                break;
            case "chidao":
                setSimpleActionBar("迟到");
                break;
            case "zaotui":
                setSimpleActionBar("早退");
                break;
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        binder.unbind();
    }

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        switch (order) {
            case MyState.requestOne:
                Log.e("BUNNIES", "dataBack: " + data.toString());
                list = JSONArray.parseArray((String) data, RecodePersonBean.class);
                adapter = new CheckInNextListAdapter(list, this,type);
                checkInListView.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                break;
        }
    }
}
